package pl.pyjter;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name="Publisher")
public class Publisher {
	private int id;
	private String name;
	private Set<Book> books = new HashSet<Book>(0);
	
	private static String[] columnsOrder = {"id", "name"};
    public static String[] getColumnsOrder() {
    	return columnsOrder;
    }	
	
	@Id
	@GeneratedValue
	@Column(name="id")
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name="name")
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "publisher")
    public Set<Book> getBooks() {
		return this.books;
	}
    
    public void setBooks(Set<Book> books) {
		this.books = books;
	}	
	
	public void display() {
		System.out.println(id + "|" + name);
	}	
}
